package Vivienda;

import java.net.ServerSocket;
import java.net.Socket;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Servidor 
{
	private ServerSocket serverSocket;
	private ExecutorService pool;
	
	public Servidor()
	{
		try 
		{
			this.serverSocket = new ServerSocket(Principal.PUERTO_LOCAL);
			this.pool = Executors.newFixedThreadPool(Principal.NUMERO_HILOS_THREAD_POOL);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			System.exit(-1);
		}
	}

	public void iniciar()
	{
		try
		{
			while(true)
			{
				Socket socketCliente = this.serverSocket.accept();
				
				Trabajo trabajo = new Trabajo(); 
				trabajo.establecerCliente(socketCliente);
				this.pool.execute(trabajo);
			}
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
